package master;



import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

/**
 * @author chenyw
 * @date 2022/9/5 21:35
 * 2的幂
 */
public class M231isPowerOfTwo {
    public static void main(String[] args) {
        boolean powerOfTwo = isPowerOfTwo(-16);
        System.out.println(powerOfTwo);
    }

    public static boolean isPowerOfTwo(int n) {
        return n > 0 && (n & (n - 1)) == 0;
    }

/*    //打表判断
    public static boolean isPowerOfTwo(int n) {
        if (n < 0) {
            return false;
        }
        n = n < 0 ? -n : n;
        HashSet<Integer> set = new HashSet<>();
        int res = 1;
        set.add(1);
        for (int i = 1; i <= 32; i++) {
            if (res > n) {
                break;
            }
            set.add(res * 2);
            res = res * 2;
            if (set.contains(n)) {
                return true;
            }
        }
        return false;

    }*/
}
